Become a Pro / website · becomeapro.ai / src / app / [area] / page.tsx
| 1 | import type { Metadata } from "next"; |
| 2 | import Link from "next/link"; |
| 3 | import { notFound } from "next/navigation"; |
| 4 | import { AREAS, getArea } from "@/lib/catalog"; |
| 5 | import { getFieldLessons } from "@/lib/lessons"; |
| 6 | import { pageMetadata } from "@/lib/seo"; |
| 7 | |
| 8 | export const dynamicParams = false; |
| 9 | |
| 10 | export function generateStaticParams() { |
| 11 | return AREAS.map((a) => ({ area: a.slug })); |
| 12 | } |
| 13 | |
| 14 | type Props = { params: Promise<{ area: string }> }; |
| 15 | |
| 16 | export async function generateMetadata({ params }: Props): Promise<Metadata> { |
| 17 | const area = getArea((await params).area); |
| 18 | return area ? pageMetadata({ title: area.name, description: area.summary }) : {}; |
| 19 | } |
| 20 | |
| 21 | export default async function AreaPage({ params }: Props) { |
| 22 | const area = getArea((await params).area); |
| 23 | if (!area) notFound(); |
| 24 | return ( |
| 25 | <div className="page"> |
| 26 | <p className="crumbs"> |
| 27 | <Link href="/">Home</Link> |
| 28 | </p> |
| 29 | <h1 className="text-4xl font-bold">{area.name}</h1> |
| 30 | <p className="mt-3 text-xl">{area.summary}</p> |
| 31 | <ul className="plain-list mt-8"> |
| 32 | {area.fields.map((field) => { |
| 33 | const lessons = getFieldLessons(field.slug); |
| 34 | return ( |
| 35 | <li key={field.slug}> |
| 36 | <Link href={`/${area.slug}/${field.slug}`}>{field.name}</Link> |
| 37 | <p> |
| 38 | {field.summary} {lessons.length ? `${lessons.length} ${lessons.length === 1 ? "lesson" : "lessons"}.` : "Lessons coming."} |
| 39 | </p> |
| 40 | </li> |
| 41 | ); |
| 42 | })} |
| 43 | </ul> |
| 44 | </div> |
| 45 | ); |
| 46 | } |